package com.maoyanjava.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.maoyanjava.mapper.FilmMapper;
import com.maoyanjava.mapper.TypeFMapper;
import com.maoyanjava.pojo.Film;
import com.maoyanjava.pojo.TypeF;
import com.maoyanjava.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class FilmServiceImpl implements FilmService {
    @Autowired
    private FilmMapper fm;
    @Autowired
    private TypeFMapper tm;
    @Override
    public List<Film> getAllFilm() {
        return fm.selectList(null);
    }

    public List<Film> getClassFilm(String name) {
        QueryWrapper<Film> qw = new QueryWrapper();
        qw.inSql("type1","select id from type_f where name='"+name+"'");
        qw.or(wrapper-> wrapper.inSql("type2","select id from type_f where name='"+name+"'"));
        qw.or(wrapper-> wrapper.inSql("type3","select id from type_f where name='"+name+"'"));
        return fm.selectList(qw);
    }

    //时间
    public List<Film> getTimeFilm(int i) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        QueryWrapper qw = new QueryWrapper();
        if (i==1){
            //小于 上映
            qw.lt("date",new Date());
        }else if (i==2){
            //大于 即将热映
            qw.gt("date",new Date());
        }
        return fm.selectList(qw);
    }
}
